const {
  baseUrl,
  getRequest,
  postRequest
} = require("../../../utils/request.js")
const {
  mock_flag,
  login_flag
} = require("../../../data/index.js")
const {
  userDesc_mock,
} = require("../../../mock/user.js")
Page({
  data: {
    //用户id
    userId: '',
    //用户详情
    userDesc: '',
    //客服弹出框
    kefu_show: false,
  },
  onLoad(options) {
    //登录拦截
    const isLogin = wx.getStorageSync('isLogin');
    if (!isLogin) {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      });
      if (login_flag) {
        wx.redirectTo({
          url: '/pages/user/wxlogin/wxlogin'
        });
      }
      if (!login_flag) {
        wx.redirectTo({
          url: '/pages/user/login/login'
        });
      }
    }
    //初始化数据
    this.setData({
      userId: wx.getStorageSync('userId'),
    })
    //mock数据
    if (mock_flag) {
      this.setData({
        userDesc: userDesc_mock,
      })
    }
    //网络请求
    if (!mock_flag) {
      //查询用户信息
      this.http_user_findById()
    }
  },
  /**
   * 跳转
   */
  //用户详情
  to_user_desc(e) {
    wx.navigateTo({
      url: '/pages/user/desc/desc'
    })
  },
  /**
   * 客服热线动作面板
   */
  //打开
  on_kefu_open() {
    this.setData({
      kefu_show: true
    });
  },
  //关闭
  on_kefu_close() {
    this.setData({
      kefu_show: false
    });
  },
  /**
   * 网络请求
   */
  //查询用户信息
  http_user_findById() {
    getRequest(baseUrl + "/front/user/findById", {
      userId: this.data.userId,
    }).then(res => {
      //console.log(res.data);
      if (res.code == 200) {
        this.setData({
          userDesc: res.data
        })
      }
    })
  },
})